package cn.tedu._03mvcboot02.common.response;

import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class JsonResult {
    private Integer code;
    private String msg;
    private Object data;

    /**
     * 1.针对于没有数据返回的
     */
    public JsonResult(StatusCode statusCode) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
    }

    /**
     * 2.针对于有数据返回的
     */
    public JsonResult(StatusCode statusCode, Object data) {
        //this(statusCode);
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
        this.data = data;
    }

    /**
     * 定义静态方法,只是为了调用方便
     */
    public static JsonResult ok(Object data){
        return new JsonResult(StatusCode.OPERATION_SUCCESS, data);
    }

    public static JsonResult ok(){
        return ok(null);
    }
}







